﻿@using LanDBom.Resources
@using LanDBom.Models
@{
    ViewBag.Title = "ViewEdit";
    Layout = "~/Views/Shared/_Genertals.cshtml";
}


<fieldset class="boun-m" style="width:96%">
    <legend class="len-x">@Resource.String762</legend>
    <div class="row ">
        <div class="form-group col-4">
            <label for="CL_number" class="col-lg-4 control-label">@Resource.String763</label>
            <div class="col-lg-10">
                <input type="text" class="form-control" id="txtnum" placeholder="@Resource.String763" name="num" readonly="readonly">
            </div>
        </div>
        <div class="form-group col-4">
            <label for="CL_name" class="col-lg-4 control-label">@Resource.String764</label>
            <div class="col-lg-10 nav">
                <input type="text" class="form-control" id="txtname" placeholder="@Resource.String764" name="name"><span style="color:red">*</span>
            </div>
        </div>
    </div>
    <div class="row ">
        <div class="form-group col-4">
            <label for="CL_address" class="col-lg-4 control-label">@Resource.String765</label>
            <div class="col-lg-10" style="display:flex">
                <input type="text" class="form-control" id="txtaddress" placeholder="@Resource.String216" name="address"><span style="color:red">*</span>
            </div>
        </div>
        <div class="form-group col-4">
            <label for="CL_phone" class="col-lg-4 control-label">@Resource.String766</label>
            <div class="col-lg-10 nav">
                <input type="tel" class="form-control" id="txtphone" placeholder="@Resource.String766" name="phone"><span style="color:red">*</span>
            </div>
        </div>
    </div>
    <div class="row ">
        <div class="form-group col-4">
            <label for="CL_email" class="col-lg-4 control-label">@Resource.String767</label>
            <div class="col-lg-10" style="display:flex">
                <input type="email" class="form-control" id="txtemail" placeholder="@Resource.String280" name="email"><span style="color:red">*</span>
            </div>
        </div>
        <div class="form-group col-4">
            <label for="CL_remarks" class="col-lg-4 control-label">@Resource.String768</label>
            <div class="col-lg-10 nav">
                <input type="text" class="form-control" id="txtremarks" placeholder="@Resource.String768" name="remarks">
            </div>
        </div>
    </div>
    <div class="row ">
        <div class="form-group col-4">
            <label for="CL_shipping_address" class="col-lg-4 control-label">@Resource.String769</label>
            <div class="col-lg-10">
                <input type="text" class="form-control" id="txtshipping_address" placeholder="@Resource.String769" name="shipping_address">
            </div>
        </div>
        <div class="form-group col-4">
            <label for="CL_distance" class="col-lg-4 control-label">@Resource.String770 (KM)</label>
            <div class="col-lg-10 nav">
                <input type="number" class="form-control" id="txtdistance" placeholder="@Resource.String770" name="distance" min="0">
            </div>
        </div>
    </div>

    <div class="row ">
        <div class="form-group col-4">
            <label for="CL_shipping_address" class="col-lg-4 control-label">助记码</label>
            <div class="col-lg-10">
                <input type="text" class="form-control" id="CL_zhu" placeholder="助记码" name="shipping_address">
            </div>
        </div>
        <div class="form-group col-4">
            <label for="CL_distance" class="col-lg-4 control-label">所属法人</label>
            <div class="col-lg-10 nav">
                <input type="text" class="form-control" id="LC_fa" placeholder="所属法人" name="distance" min="0">
            </div>
        </div>
    </div>
    <div class="row ">
        <div class="form-group col-4">
            <label for="CL_shipping_address" class="col-lg-4 control-label">货币</label>
            <div class="col-lg-10">
                <select id="CL_huo" class="form-control">
                    <option></option>
                </select>
            </div>
        </div>
        <div class="form-group col-4">
            <label for="CL_shipping_address" class="col-lg-4 control-label">简称</label>
            <div class="col-lg-10 nav">
                <input type="text" class="form-control" id="CL_JIank" placeholder="简称" name="shipping_address">
            </div>
        </div>
    </div>
    <div class="row ">
        <div class="form-group col-4">
            <label for="CL_shipping_address" class="col-lg-4 control-label">国家</label>
            <div class="col-lg-10">
                <input type="text" name="Guojiad" value="" class="form-control" id="CL_Nation" list="Lod_sj" />
                <datalist id="Lod_sj" class="form-control" style="display:none">
                </datalist>
            </div>
        </div>
        <div class="form-group col-4">
            <label for="CL_shipping_address" class="col-lg-4 control-label">地区</label>
            <div class="col-lg-10 nav">
                <input type="text" name="CLkjie" value="" class="form-control" id="CL_District" list="Loishud_sj1" />
                <datalist id="Loishud_sj1" class="form-control" style="display:none">
                </datalist>
            </div>
        </div>
    </div>
    <div class="row ">
        <div class="form-group col-4">
            <label for="CL_shipping_address" class="col-lg-4 control-label">城市</label>
            <div class="col-lg-10">
                <input type="text" name="CLkunne" value="" class="form-control" id="CL_City" list="Loishud_sj2" />
                <datalist id="Loishud_sj2" class="form-control" style="display:none">
                </datalist>
            </div>
        </div>
        <div class="form-group col-4">
            <label for="CL_shipping_address" class="col-lg-4 control-label">终端客户</label>
            <div class="col-lg-10">
                <input type="text" name="CLkunne" value="" class="form-control" id="CL_ZDKH" list="Loishud_sj2" />
                <datalist id="Loishud_sj2" class="form-control" style="display:none">
                </datalist>
            </div>
        </div>
    </div>

    <div class="row">
        <div class="col-lg-2 "><input type="button" id="btnCreate" class="btn btn-light" value="确定" /> </div>
        <div class="col-lg-2"><button id="btnreset" type="submit" class="btn btn-light">重置</button></div>
        <div class="col-l-2"><button class="TUIhui btn btn-light">返回</button></div>
    </div>


</fieldset>

<div style=" display:none" id="JMCLPC">@(Session["CL_id"])</div>


@section scripts
{

    <script src="~/Scripts/jquery-3.4.1.min.js"></script>
    <script src="~/Scripts/bootstrap.min.js"></script>

    <script>

        shiyong()
        function shiyong() {
            $.ajax({
                url: "/Custom/Profit",
                type: "POST",
                data: { "state": 4 },
                success: function (data) {
                    console.log(data)
                    $("#CL_huo option").remove();
                    $.each(data, function (i, item) {
                        var $tr = (`<option value="${item[0]}">${item[0]}</option>`);
                        $("#CL_huo").append($tr);
                    })
                },
                error: function (data) {
                    alert("erroer");
                },
            })
        }
        shiyong11()
        function shiyong11() {
            $.ajax({
                url: "/Custom/Custom",
                type: "POST",
                data: { "state": 1 },
                success: function (data) {
                    $("#Lod_sj option").remove();
                    $("#Loishud_sj1 option").remove();
                    $("#Loishud_sj2 option").remove();
                    $.each(data, function (i, item) {
                        var $TR = $(`<option value="${item[0]}">`);
                        switch (item[1]) {
                            case "地区":
                                $("#Loishud_sj1").append($TR)
                                break;
                            case "国家":
                                $("#Lod_sj").append($TR)
                                break;
                            case "城市":
                                $("#Loishud_sj2").append($TR)
                                break;
                            default:
                                break;
                        }
                    })
                },
                error: function (data) {
                    alert("erroer");
                },
            })
        }
        $(function () {
            $('#btnCreate').click(function () {
                var Custom = {
                    CL_ID: $("#JMCLPC").text(),
                    CL_bian: $('#txtnum').val(),
                    CL_name:  $('#txtname').val(),
                    CL_di: $('#txtaddress').val(),
                    CL_lian: $('#txtphone').val(),
                    CL_you: $('#txtemail').val(),
                    CL: $('#txtremarks').val(),
                    CL_bei: $('#txtshipping_address').val(),
                    CL_ju: $('#txtdistance').val(),
                    CL_Huobi: $('#CL_huo').val(),
                    CL_Jian:$('#CL_JIank').val(),
                    CL_zhu: $('#CL_zhu').val(),
                    CL_shuo: $('#LC_fa').val(),
                    CL_City: $('#CL_City').val(),
                    CL_District: $('#CL_District').val(),
                    CL_Nation: $('#CL_Nation').val(),
                    CL_ZDKH: $("#CL_ZDKH").val()
                };
                console.log(Custom)
                if (Custom.CL_name == "") {
                    alert("客户名称不能为空！");
                } else if (Custom.CL_di == "") {
                    alert("公司地址不能为空！");
                } else if (Custom.CL_lian == "") {
                    alert("客户联系不能为空！");
                } else {
                    $.ajax({
                        url: "/Application/Mormation",
                        type: "POST",
                        data: {"dl": Custom},
                        success: function (data) {
                            alert(data);
                            if (data == "修改成功") {
                                window.location.href = "/Application/CliView";
                            }
                        },
                        error: function (data) {
                            alert("erroer");
                        },
                    })
                }
            })
            $(".TUIhui").click(function () {
                history.go(-1)
            })
        })
        //加载
        JIao()
        function JIao() {
            $.ajax({
                url: "/Custom/ViewEdit",
                type: "POST",
                data: { "state": 1, "id": $("#JMCLPC").text() },
                success: function (date) {
                    console.log(date)
                    $('#txtnum').val(date.CL_bian);
                    $('#txtname').val(date.CL_name);
                    $('#txtaddress').val(date.CL_di);
                    $('#txtphone').val(date.CL_lian);
                    $('#txtemail').val(date.CL_you);
                    $('#txtremarks').val(date.CL_bei);
                    $('#txtshipping_address').val(date.CL_sho);
                    $('#txtdistance').val(date.CL_ju);
                    $('#CL_huo').val(date.CL_Huobi);
                    $('#CL_JIank').val(date.CL_Jian);
                    $('#CL_zhu').val(date.CL_zhu);
                    $('#LC_fa').val(date.CL_shuo);
                    $('#CL_City').val(date.CL_City);
                    $('#CL_District').val(date.CL_District);
                    $('#CL_Nation').val(date.CL_Nation);
                },
                error: function (ptaah) {
                    alert("erroer12");
                },
            })
        }
    </script>

}

